﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twc.Deployment.Client.Logic.Commands.Parameters;

namespace Twc.Deployment.Client.Logic.Commands
{
    public class WSPSetupCommandGenerator : ICommandGenerator
    {
        public InstallationType InstallationType
        {
            get;
            set;
        }

        public string SiteCollectionUrl
        {
            get;
            set;
        }

        public string SubsiteUrl
        {
            get;
            set;
        }

        public string GenerateCommand()
        {
            StringBuilder command = new StringBuilder();
            parameters = new List<BaseParameter>();
            
            parameters.Add(new Parameters.Setup());

            switch (InstallationType)
            {
                case InstallationType.INSTALL:
                    parameters.Add(new Parameters.Install());
                    break;
                case InstallationType.UNINSTALL:
                    parameters.Add(new Parameters.Uninstall());
                    break;
            }

            parameters.Add(new Parameters.SiteUrl());
            parameters.Add(new Parameters.Literal( SiteCollectionUrl, SiteCollectionUrl));
            
            parameters.Add(new Parameters.WebUrl());
            parameters.Add(new Parameters.Literal(SubsiteUrl, SubsiteUrl));

            foreach (var parameter in parameters)
            {
                command.Append(parameter.Parameter + " ");
            }
            return command.ToString();

        }

        public IList<BaseParameter> parameters
        {
            get;
            set;
        }
    }
}
